#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
# sys.path.append('/opt/work/caffe/python')
sys.path.insert(0, '.')

import os

############################################################################

base_path = r'/rootfs/media/kasim/Data1/data/VideoCropFace/FaceAttrJson'
out_list_file = r'/rootfs/media/kasim/Data1/data/VideoCropFace/json_file_list.txt'
file_paths = [
    r'./',
]
FILE_EXT = {'.json', }
REPLAY_PATH = '.'
search_sub_dir = True

file_count = 0
for file_path in file_paths:
    file_path = os.path.normpath(os.path.join(base_path, file_path))
    list_full_file = os.path.normpath(out_list_file)
    with open(list_full_file, 'w') as out_file:
        for dir_name, sub_dirs, files in os.walk(file_path):
            dir_name = os.path.normpath(dir_name)
            if not search_sub_dir:
                if file_path != dir_name:
                    # print(file_path, dir_name)
                    continue
            for file_name in files:
                file_ext = os.path.splitext(file_name)[1].lower()
                if FILE_EXT is not None:
                    if file_ext not in FILE_EXT:
                        continue
                file_name = file_name.strip()
                file_size = os.path.getsize(os.path.join(dir_name, file_name))
                relative_file_path = os.path.normpath(os.path.normpath(os.path.join(dir_name.replace(file_path, REPLAY_PATH), file_name)))
                # out_file.write('{} {}\n'.format(relative_file_path, file_size))
                out_file.write('{}\n'.format(relative_file_path))
                file_count += 1
                if file_count % 100 == 0:
                    print('Process File Count:', file_count)
print('Process File Count:', file_count)
os.system('chmod a+wr {}'.format(out_list_file))
print('Finish!')

###############################################################################

